package com.example.teatea.dao;

import com.example.teatea.project.Staff;
import com.example.teatea.tools.GetTime;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;

public class AgreeRegister {
    public void agreeRegister(Staff staff){
        Connection connection = null;;
        Properties properties = new Properties();
        PreparedStatement presta = null;
        try {
            properties.load(new FileInputStream("src\\main\\resources\\com\\example\\teatea\\sql.properties"));
            String user = properties.getProperty("user");
            String password = properties.getProperty("password");
            String Driver = properties.getProperty("Driver");
            String url = properties.getProperty("url");
            Class.forName(Driver);
//            String s = new GetTime().getTime();
//            int i = 1;
            String sql = "update staff set sState = " + staff.getsState() + ",sTime = '" + staff.getsTime() + "' where sPhone='" + staff.getsPhone() + "'";
            connection = DriverManager.getConnection(url,user,password);
            presta = connection.prepareStatement(sql);
            presta.executeUpdate(sql);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
